﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports GenDotNet.TemplateSupport
Imports GenDotNet.Task.Common

Public Class FunctionInfo
   Inherits MemberInfo

   Private mReturnType As NetTypeInfo
   Private mFunctionDelegate As EmptyDelegate

   Public Sub New( _
            ByVal name As String, _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal modifiers As MemberModifiers, _
            ByVal returnType As NetTypeInfo, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo)
      MyBase.New(name, typeInfo, scope, modifiers, parameters)
      Me.mReturnType = returnType
      Me.mFunctionDelegate = methodDelegate
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal modifiers As MemberModifiers, _
            ByVal interfaceItem As InterfaceItemInfo, _
            ByVal returnType As NetTypeInfo, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo)
      MyBase.New(name, typeInfo, scope, modifiers, parameters)
      Me.mReturnType = returnType
      Me.mFunctionDelegate = methodDelegate
      Me.InterfaceItems.Add(interfaceItem)
   End Sub

   Public Sub New( _
            ByVal name As String, _
            ByVal typeInfo As TypeInfo, _
            ByVal scope As Scope, _
            ByVal returnType As NetTypeInfo, _
            ByVal methodDelegate As EmptyDelegate, _
            ByVal ParamArray parameters() As ParameterInfo)
      Me.New(name, typeInfo, scope, Nothing, returnType, methodDelegate, parameters)
   End Sub

   Public Property ReturnType() As NetTypeInfo
      Get
         Return mReturnType
      End Get
      Set(ByVal value As NetTypeInfo)
         mReturnType = value
      End Set
   End Property

   Public Property FunctionDelegate() As EmptyDelegate
      Get
         Return mFunctionDelegate
      End Get
      Set(ByVal value As EmptyDelegate)
         mFunctionDelegate = value
      End Set
   End Property

End Class


Namespace VB
   Public Module FunctionInfoExtensions

      <Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As FunctionInfo) As String
         Return _
<code>
   <%= info.Scope.Output.WithSpace %><%= info.Modifiers.Output.WithSpace %>Function <%= info.Name %>(<%= info.Parameters.Output %>) As <%= info.ReturnType.Output %><%= info.InterfaceItems.OutputDeclaration %><%= Strings.nl %><%= Spaces(6) %>
   <%= info.FunctionDelegate.Invoke() %>
   End Function
</code>.Value
      End Function

      '<Runtime.CompilerServices.Extension()> _
      ' Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData, ByVal data As IPropertyData) As String
      '   Return Output(info, New PropertyEventArgs(info, data))
      ' End Function

      '<Runtime.CompilerServices.Extension()> _
      ' Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData, ByVal data As IChildData) As String
      '   Return Output(info, New ChildEventArgs(info, data))
      'End Function

      '<Runtime.CompilerServices.Extension()> _
      ' Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData, ByVal data As ICriteriaData) As String
      '   Return Output(info, New CriteriaEventArgs(info, data))
      'End Function

      '<Runtime.CompilerServices.Extension()> _
      'Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData) As String
      '   Return Output(info, New ObjectEventArgs(info, objectData))
      'End Function

   End Module
End Namespace

Namespace CSharp
   Public Module FunctionInfoExtensions
      ' NOTE: Interfaces not yet implemented for C# templates
      <Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As FunctionInfo) As String
         Return _
<code>
   <%= info.Scope.Output.WithSpace %><%= info.ReturnType.Output.WithSpace %><%= info.Name %>(<%= info.Parameters.Output %>) 
      {
   <%= info.FunctionDelegate.Invoke().WithSemiColons %>
      }
</code>.Value
      End Function

      '<Runtime.CompilerServices.Extension()> _
      ' Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData, ByVal data As IPropertyData) As String
      '   Return Output(info, New PropertyEventArgs(info, data))
      'End Function

      '<Runtime.CompilerServices.Extension()> _
      ' Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData, ByVal data As IChildData) As String
      '   Return Output(info, New ChildEventArgs(info, data))
      'End Function

      '<Runtime.CompilerServices.Extension()> _
      ' Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData, ByVal data As ICriteriaData) As String
      '   Return Output(info, New CriteriaEventArgs(info, data))
      'End Function

      '<Runtime.CompilerServices.Extension()> _
      'Public Function Output(ByVal info As FunctionInfo, ByVal objectData As IObjectData) As String
      '   Return Output(info, New ObjectEventArgs(info, objectData))
      'End Function

   End Module
End Namespace
